package hu.village.mapper;

import hu.village.pojo.Account;
import hu.village.pojo.User;
import lombok.Setter;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface UserMapper {

    //根据邮箱删除验证码
    @Delete("delete from verify_code where email = #{email} and state = #{state}")
    void deleteCodeByEmail(String email, String state);
    //保存注册发送的验证码
    @Insert("insert into verify_code(email, code, time, state) value (#{email},#{verify_code},#{time},#{state})")
    void saveVerifyCode(String email, Integer verify_code, LocalDateTime time,String state);
    //注册时获取数据库中的验证码
    @Select("select code from verify_code where email = #{email} and state = #{state}")
    String getCodeByEmailAndState(String email, String state);
    //新增用户
    @Insert("insert into user(username, email, password) value (#{username},#{email},#{password})")
    void insertUser(User user);
    //登录查询用户
    @Select("select * from user where username = #{username} and password = #{password}")
    User selectUser(User user);

    //修改用户信息
    void updateUser(User user);

    //查看审核通过的账目
    @Select("select * from account where state = #{state} and visible = 1")
    List<Account> selectAccountByState(Integer state);

    //举报账目
    @Update("update account set reported = #{reported},report_man = #{reportMan} where id = #{id}")
    void updateAccountState(String reportMan, Integer reported,Integer id);

    //查询举报申诉情况
    @Select("select state from account where report_man = #{reportMan}")
    Integer getAccountByReportMan(Account account);

    //撤销举报
    @Update("update account set reported = 0,report_man = null where id = #{id}")
    void repelAccount(Account account);

    //提交查看以往记录的申请
    @Update("update user set status = #{status} where id = #{id}")
    void updateUserStatusById(User user);
}
